<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewTransactionall extends JView
{
	function display($tpl=null) 
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$db			= & JFactory::getDBO();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');
		$pathway  	= & $mainframe->getPathway();

		$gid			= $user->gid;
		$level			= $ownuser->get('level_id');

		if($gid < 25) {
			if ( !Ownservice::checkAccess('transaction', 'transactionall', 'transaction', 'all') ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		if($this->getLayout() == 'transfers') {
			$this->_displaytransfers($tpl);
			return;
		}

		//Set page title information
		$menus		= &JSite::getMenu();
		$menu		= $menus->getActive();

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');

		//get branch
		$branches 	= & $this->get('Branches');
		
		$lists = array();

		//Build filter status
		$statuslist[] = JHTML::_( 'select.option', '',			JText::_('OWNSERVICE_SELECT_STATUS') );
		$statuslist[] = JHTML::_( 'select.option', '1',		JText::_('OWNSERVICE_PAID'));
		$statuslist[] = JHTML::_( 'select.option', '2',		JText::_('OWNSERVICE_APPROVAL_PENDING'));
		$statuslist[] = JHTML::_( 'select.option', '3',		JText::_('OWNSERVICE_TRANSFERRING'));
		$statuslist[] = JHTML::_( 'select.option', '4',		JText::_('OWNSERVICE_SUCCESSFUL'));
		$statuslist[] = JHTML::_( 'select.option', '5',		JText::_('OWNSERVICE_FAIL'));
		$statuslist[] = JHTML::_( 'select.option', '6',		JText::_('OWNSERVICE_CORRECTED'));
		$statuslist[] = JHTML::_( 'select.option', '7',		JText::_('OWNSERVICE_APPROVAL_PENDING_CORRECTED'));
		$statuslist[] = JHTML::_( 'select.option', '8',		JText::_('OWNSERVICE_CANCELLED'));

		$lists['status']	=	JHTML::_('select.genericlist', $statuslist, 'filter_status', 'class="inputbox" onchange="submitform( );" style="width:200px;"', 'value', 'text', $filter_status );

		//Build filter branch select list
		$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );" style="width:200px;"');
		
		// because the application sets a default page title, we need to get it
		// right from the menu item itself
		if (is_object( $menu )) {
			$menu_params = new JParameter( $menu->params );
			if (!$menu_params->get( 'page_title')) {
				$params->set('page_title',	JText::_('OWNSERVICE_TRANSACTIONS_ALL'));
			}
		} else {
			$params->set('page_title',	JText::_('OWNSERVICE_TRANSACTIONS_ALL'));
		}
		$document->setTitle( $params->get( 'page_title' ) );

		//assign data to document
		$this->assignRef('params', $params);
		$this->assignRef('document', $document);
		$this->assignRef('lists', $lists);

		parent::display($tpl);
	}

	function _displaytransfers($tpl)
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$db			= & JFactory::getDBO();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');
		$pathway  	= & $mainframe->getPathway();

		$filter_date			= $mainframe->getUserStateFromRequest($option.'.transactionall.date','date','','string' );
		$filter_status		= $mainframe->getUserStateFromRequest($option.'.transactionall.filter_status','filter_status',0,'int' );
		$filter_branch		= $mainframe->getUserStateFromRequest($option.'.transactionall.filter_branch','filter_branch',0,'int' );
		$filter_order			= $mainframe->getUserStateFromRequest($option.'.transactionall.filter_order', 'filter_order', 't.created', 'cmd');
		$filter_order_Dir	= $mainframe->getUserStateFromRequest($option.'.transactionall.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search				= $mainframe->getUserStateFromRequest($option.'.transactionall.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		
		//Set page title information
		$menus		= &JSite::getMenu();
		$menu		= $menus->getActive();

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');

		//get data from the model
		$model 		= $this->getModel();
		$rows 		= & $this->get('Data');
		$total			= & $this->get('Total');
		$pageNav	= & $this->get('Pagination');
		$branches 	= & $this->get('Branches');

		// because the application sets a default page title, we need to get it
		// right from the menu item itself
		if (is_object( $menu )) {
			$menu_params = new JParameter( $menu->params );
			if (!$menu_params->get( 'page_title')) {
				$params->set('page_title',	JText::_('OWNSERVICE_TRANSACTIONS_ALL'));
			}
		} else {
			$params->set('page_title',	JText::_('OWNSERVICE_TRANSACTIONS_ALL'));
		}
		$document->setTitle( $params->get( 'page_title' ) );

		$lists = array();

		//Build filter status
		$statuslist[] = JHTML::_( 'select.option', '',			JText::_( 'OWNSERVICE_SELECT_STATUS' ) );
		$statuslist[] = JHTML::_( 'select.option', '1',		JText::_('OWNSERVICE_PAID'));
		$statuslist[] = JHTML::_( 'select.option', '2',		JText::_('OWNSERVICE_APPROVAL_PENDING'));
		$statuslist[] = JHTML::_( 'select.option', '3',		JText::_('OWNSERVICE_TRANSFERRING'));
		$statuslist[] = JHTML::_( 'select.option', '4',		JText::_('OWNSERVICE_SUCCESSFUL'));
		$statuslist[] = JHTML::_( 'select.option', '5',		JText::_('OWNSERVICE_FAIL'));
		$statuslist[] = JHTML::_( 'select.option', '6',		JText::_('OWNSERVICE_CORRECTED'));
		$statuslist[] = JHTML::_( 'select.option', '7',		JText::_('OWNSERVICE_APPROVAL_PENDING_CORRECTED'));
		$statuslist[] = JHTML::_( 'select.option', '8',		JText::_('OWNSERVICE_CANCELLED'));

		$lists['status']	=	JHTML::_('select.genericlist', $statuslist, 'filter_status', 'class="inputbox" onchange="submitform( );"', 'value', 'text', $filter_status );

		//Build filter branch select list
		$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );"');

		//search filter
		$lists['search']	= $search;

		//date filter
		$lists['date'] = $filter_date;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('lists', $lists);
		$this->assignRef('params', $params);
		$this->assignRef('document', $document);

		parent::display($tpl);
	}
}